package HomeWork.Chapter04;

import java.util.Random;

/**
 * Enjoy programming!!!
 * Time: 2021/11/13 -  23:05
 */
public class TestPoint {
    public static void main(String[] args) {
        Point p = new Point();
        System.out.println("原始位置：(" + p.getPoint()[0] + "," + p.getPoint()[1] + ")");
        p.movePoint(10, 20);
        System.out.println("移动后：(" + p.getPoint()[0] + "," + p.getPoint()[1] + ")");
        Point p2 = new Point();
        p2.random();
        Point p3 = new Point();
        p3.random();
        System.out.println("p.x:" + p.x + " p2.x:" + p2.x + " p3.x:" + p3.x);
        System.out.println("p.y:" + p.y + " p2.y:" + p2.y + " p3.y:" + p3.y);
        System.out.println("是否为三角形？" + Triangle.triangleTest(p, p2, p3));
    }
}

class Point {
    int[] a = new int[2];
    int x;
    int y;

    public Point() {
        x = 0;
        y = 0;
    }

    public void setX(int x) {
        this.x = x;
        a[0] = x;
    }

    public void setY(int y) {
        this.y = y;
        a[1] = y;
    }

    public int[] getPoint() {
        return a;
    }

    public void movePoint(int x, int y) {
        this.x = x;
        this.y = y;
        a[0] = this.x;
        a[1] = this.y;
    }

    public void random() {
        Random rand = new Random();
        this.x = rand.nextInt(10);
        this.y = rand.nextInt(10);
    }

}

class Triangle {
    static public boolean triangleTest(Point p1, Point p2, Point p3) {
        return distance.test(p1, p2) + distance.test(p2, p3) >= distance.test(p1, p3);
    }

}

class distance {
    static public double test(Point p1, Point p2) {


        return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));

    }
}